package com.etoak.controller;


import com.etoak.common.core.vo.PageVo;
import com.etoak.common.core.vo.ResultVo;
import com.etoak.entity.Ingredients;
import com.etoak.service.IngredientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author et2403
 * @since 2024-08-13
 */
@RestController
@RequestMapping("/ingredients")
public class IngredientsController {

    @Autowired
    IngredientsService ingredientsService;

    @PostMapping
    public ResultVo<Object> add(@Validated @RequestBody Ingredients ingredients) {
        ingredientsService.add(ingredients);
        return ResultVo.sussess();
    }

    /**
     * 分页查询
     */
    @GetMapping
    public ResultVo<PageVo<Ingredients>> getList(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "10") int pageSize,
            Ingredients ingredients
    ) {
        PageVo<Ingredients> pageVo = ingredientsService.getList(pageNum,pageSize,ingredients);
        return ResultVo.sussess(pageVo);
    }

    /**
     * 更新
     * put/ingredients/{id}
     */
    @PutMapping("/{id}")
    public ResultVo<Object> update(@PathVariable int id,@RequestBody Ingredients ingredients) {
        ingredientsService.update(id,ingredients);
        return ResultVo.sussess();
    }

    /**
     * 删除接口
     * delete/ingredient/{id}
     */
    @DeleteMapping("{id}")
    public ResultVo<Object> delete(@PathVariable int id) {
        ingredientsService.delete(id);
        return ResultVo.sussess();
    }

}

